
local skynet = require "skynet"
local inspect = require "inspect"

local ORI_DECK = {}
for i=1,9 do
	table.insert(ORI_DECK,0x10 + i)
end
for i=1,9 do
	table.insert(ORI_DECK,0x20 + i)
end
for i=1,9 do
	table.insert(ORI_DECK,0x30 + i)
end

local HU = 4
local GANG = 3
local PENG = 2
local CHI = 1

local XIAO_HU = {
	DA_SI_XI 		= 1,--"DA_SI_XI"	,
	BAN_BAN_HU		= 2,--"BAN_BAN_HU"	,
	QUE_YI_SE		= 3,--"QUE_YI_SE"	,
	LIU_LIU_SHUN	= 4,--"LIU_LIU_SHUN",
	JIE_JIE_GAO 	= 5,--"JIE_JIE_GAO" ,
	THREE_SAME		= 6,--"THREE_SAME"	,
	ONE_FLOWER		= 7,--"ONE_FLOWER"	,
	PING_HU			= 8,--"PING_HU"		,
}
--胡牌类型
local HU_TYPE = {
	PING_HU					= 1, --平胡
	QING_ONE_SUIT 			= 2, --清一色
	PENG_PENG_HU 			= 3, --对对胡
	JIANG_JIANG_HU 			= 4, --降降胡
	QI_XIAO_DUI  			= 5, --七小对
	QI_XIAO_DUI_ONE			= 6, --豪7
	QI_XIAO_DUI_TWO			= 7, --大豪7
	QI_XIAO_DUI_THREE		= 8, --3豪7	
}

local SPECIAL_TYPE = {
	HAI_DI_HU 			= 9,
	HAI_DI_LAO_YUE		= 10,
	GANG_SHANG_FLOWER 	= 11,
	GANG_SHANG_PAO 		= 12,
	TIAN_HU 			= 13,
	DI_HU 				= 14,
	QIANG_GANG_HU 		= 15,
	QUAN_QIU_REN 		= 16,
}

local card = {}
------------------------------------- 
--0x1f 万 character
--0x2f 条 bamboo 
--0x3f 饼 circle
--0x4f 花 flower
	--东南西北中发白 1-7
	
function table_copy_table(ori_tab)
	if (type(ori_tab) ~= "table") then
		return nil
	end
	local new_tab = {}
	for i,v in pairs(ori_tab) do
		local vtyp = type(v)
		if (vtyp == "table") then
			new_tab[i] = table_copy_table(v)
		elseif (vtyp == "thread") then
			new_tab[i] = v
		elseif (vtyp == "userdata") then
			new_tab[i] = v
		else
			new_tab[i] = v
		end
	end
	return new_tab
end

function card:remove_one_sam_card(cards,card,index)
	local num = 1
	for i,v in ipairs(cards) do
		if num >= index then
			if v == card then
				table.remove(cards,i)
				return
			end
		end
		num = num + 1
	end
end

function card:new_deck()
	local t = {}
	for i=1,9 do
		for k=1,4 do
			table.insert(t,0x10|i)
			table.insert(t,0x20|i)
			table.insert(t,0x30|i)
		end
	end
	-- for i=1,7 do
	-- 	for k=1,4 do
	-- 		table.insert(t,0x40|i)
	-- 	end
	-- end
	math.randomseed(os.time()-76567211)
	local rand
	for i=1,#t do
		rand = math.random(i,#t)
		t[i],t[rand]=t[rand],t[i]
	end
	return t
end

function card:get_bai_da()
	local t = {}
	for i=1,9 do
		table.insert(t,0x10|i)
		table.insert(t,0x20|i)
		table.insert(t,0x30|i)
	end
	for i=1,7 do
		table.insert(t,0x40|i)
	end
	math.randomseed(os.time()-76567211)
	local rand
	for i=1,#t do
		rand = math.random(i,#t)
		t[i],t[rand]=t[rand],t[i]
	end
	return t[1]
end

function card:sort_card(t)
	table.sort(t, function(a,b)
		local sa,ra = a&0xf,a&0xf0
		local sb,rb = b&0xf,b&0xf0
		if ra == rb then
			return sa < sb
		else
			return ra < rb
		end
		
	end)
end

function card:get_feng_ke(card,quan_feng,men_feng)
	local ret = {}
	local ke = self:get_value(card)
	if ke <= 4 then
		if ke == quan_feng then
			table.insert(ret,QUAN_FENG)
		end
		if ke == men_feng then
			table.insert(ret,MEN_FENG)
		end
	end
	if ke == 5 then 
		table.insert(ret,HONG_ZHONG_KE)
	end
	if ke == 6 then 
		table.insert(ret,FA_CAI_KE)
	end
	if ke == 7 then 
		table.insert(ret,BAI_BAN_KE)
	end
	return ret
end

function card:has(t,c)
	for i,v in ipairs(t) do
		if v == c then
			return true
		end
	end
end

function card:drop(t,c)
	for i,v in ipairs(t) do
		if v == c then
			table.remove(t,i)
			return true
		end
	end
	error("not found")
end

function card:add(t,c)
	if type(c) == "table" then
		for _,v in ipairs(c) do
			table.insert(t,v)
		end
	else
		table.insert(t,c)
	end
end

function card:get_value(c)
	return c&0xf--c%16
end

function card:get_type(c)
	return c>>4--sc/16
end

function card:get_specify_nums(t,c)
	local num = 0
	for i,v in ipairs(t) do
		if v == c then
			num = num + 1
		end
	end
	return num
end

function card:is_continus(tb)
	if not tb then 
		return
	end
	local one = tb[1]
	for k,v in pairs(tb) do
		if (one + k - 1) ~= v then
			return false
		end
	end
	return true
end

function card:get_card_type(tb)
	local ret = {}
	local last = 0
	for k,v in pairs(tb) do
		if last ~= v then
			table.insert(ret,v)
			last = v
		end
	end
	return ret
end

function card:get_two_card(tb)
	local cards= {}
	local last = 0
	local card = {}
	for k,v in pairs(tb) do
		if not cards[v] then
			cards[v] = 1
		else
			cards[v] = cards[v] + 1
		end
	end
	for  k,v in pairs(cards) do
		if v == 2 then
			last = k
		end
	end
	return {last , last - 3 , last + 3}
end


function card:check_chi(set,gold,single)
	assert(single ~= gold)
	self:sort_card(set)
	if #set == 4 and self:is_continus(set) and set[1] + 3 == set[4] and (set[1] == single or set[4] == single)  then
		return
	end
	local get_two_card = self:get_two_card(set)
	if #set == 4 and set[1] + 2 == set[4] and #self:get_card_type(set) == 3 and self:has(get_two_card,single) then
		return
	end
	local t = {}
	local val = self:get_value(single)
	if val > 2 then
		if self:has(set,single - 1) and self:has(set,single - 2) then
			if single - 1 ~= gold and single - 2 ~= gold then
				local temp = {}
				table.insert(temp,single - 1)
				table.insert(temp,single - 2)
				table.insert(t,temp)
			end
		end
	end
	if val < 9 and val > 1 then
		if self:has(set,single - 1) and self:has(set,single + 1) then
			if single - 1 ~= gold and single + 1 ~= gold then
				local temp = {}
				table.insert(temp,single - 1)
				table.insert(temp,single + 1)
				table.insert(t,temp)
			end
		end
	end
	if val < 8 then
		if self:has(set,single + 1) and self:has(set,single + 2) then
			if single + 1 ~= gold and single + 2 ~= gold then
				local temp = {}
				table.insert(temp,single + 1)
				table.insert(temp,single + 2)
				table.insert(t,temp)
			end
		end
	end
	if #t ~= 0 then
		return t
	end
end

function card:check_peng(set,single)
	local nums = 0
	for i,v in ipairs(set) do
		if v == single then
			nums = nums + 1
		end
	end
	if nums >= 2 then
		return true
	end
end

function card:check_gang(set,single)
	local nums = 0
	for i,v in ipairs(set) do
		if v == single then
			nums = nums + 1
		end
	end
	if nums >= 3 then
		return true
	end 
end

function card:get_c(v)
	
	if v then
		local c = {"W","L","O","$"}
		if v&0xf and c[v>>4] then
			local str  = tostring(v&0xf)..c[v>>4]
			return str
		end
	else
		return"no card"
	end
end

function card:get_card_string(t)
	local str = ""
	if not t then
		return str
	end
	if #t == 0 then
		return str
	end
	for k,v in ipairs(t) do
		if v then
			str = str.." "..self:get_c(v)
		end
	end
	return str
end

function card:get_pai_xing_string(t)
	local str = " "
	if not t then
		return str
	end
	for k,v in pairs(t) do
		if type(v) == "table" then
			local index = 1
			for i,p in pairs(v) do
				if p and index == 1 then
					str = str..p
				else
					str = str..","..p
				end
			index = index + 1
			end
			str = str..";"
		else
			str = str..v.." "
		end
		
	end
	return str
end

function card:remove_gang(newCards)
	local cards = {}
	for i,v in ipairs(newCards) do
		table.insert(cards,v)
	end

	local i = 0
	while(i < #cards - 3) do
		i = i + 1
		local a = cards[i]
		local b = cards[i+1]
		local c = cards[i+2]
		local d = cards[i+3]
		if a == b and b == c and c == d then	
			table.remove(cards,i + 3)
			table.remove(cards,i + 2)
			table.remove(cards,i + 1)
			table.remove(cards,i)	
			i = i - 1
		end
	end

	return cards
end

-- 移除碰
function card:remove_peng( newCards )

	local cards = {}
	for i,v in ipairs(newCards) do
		table.insert(cards,v)
	end


	local i = 0
	while(i < #cards - 2) do
		i = i + 1
		local a = cards[i]
		local b = cards[i+1]
		local c = cards[i+2]
		if a == b and b == c then	
			table.remove(cards,i + 2)
			table.remove(cards,i+1)
			table.remove(cards,i)	
			i = i - 1
		end
	end

	return cards
end
-- 移除dui
function card:remove_dui( newCards )

	local cards = {}
	for i,v in ipairs(newCards) do
		table.insert(cards,v)
	end


	local i = 0
	while(i < #cards - 1) do
		i = i + 1
		local a = cards[i]
		local b = cards[i+1]
		if a == b then	
			table.remove(cards,i+1)
			table.remove(cards,i)	
			i = i - 1
		end
	end

	return cards
end
------------------------------------------------------------------------------------------------
function card:remove_three_same(t)
		if not t then
			skynet.error("remove_three_same t is nil")
			return
		end
		if #t%3 ~= 0 and #t == 0 then
			skynet.error("remove_three_same 参数错误",inspect(t))
			return 
		end
		local found = false
		local begin
		for i=1,#t - 2 do
			if t[i] == t[i + 1] and t[i] == t[i + 2] then
				found = true
				begin = i
				break
			end
		end

		if found then
			local ret = {}
			for k=1,3 do
				table.insert(ret,table.remove(t,begin))
			end
			return true,ret
		end
end

	function card:remove_straight(t)
		if not t then
			skynet.error("remove_straight t is nil")
			return
		end
		if #t%3 ~= 0 and #t == 0 then
			skynet.error("remove_straight t is error,t is",inspect(t))
			return
		end
		local ret = {}
		for i=1,#t - 2 do
			if self:get_type(t[i]) == 4 then
				break
			end
			local found1
			local found2
			local position = {}
			table.insert(position,i)
			for k = i,#t do
				if not found1 and t[i] + 1 == t[k] then
					found1  = true 
					table.insert(position,k)
				end 

				if not found2 and t[i] + 2 == t[k] then
					found2  = true 
					table.insert(position,k)
				end 

				if found2 and found1 then
					break
				end
			end
			if found2 and found1 then
				for i = #position,1,-1 do
					table.insert(ret,table.remove(t,position[i]))
				end
				return true,ret
			end
		end
	end


	function card:check_3n(set)
		if not set then
			skynet.error("remove_straight t is nil")
			return
		end
		if #set%3 ~= 0 then
	 		skynet.error("check_3n 参数错误,参数为",inspect(set))
			return
		end
		self:sort_card(set)

		local t1 = table_copy_table(set)
		local t2 = table_copy_table(set)
		if self:remove_three_same(t1) then
			if #t1 == 0 or self:check_3n(t1)then
				return true
			end
		end

		if self:remove_straight(t2) then
			if #t2 == 0 or self:check_3n(t2) then
				return true
			end
		end
		return false
	end
-------------------------------------------------------------------
function card:check_hu(set,t)
	if not set then
		skynet.error("set  is nil")
		return false
	end
	if (#set)%3 ~= 2 then
	 	skynet.error("check_hu 参数错误,参数为",inspect(set))
		return false
	end
	if not t then
		t = {}
	end
	self:sort_card(set)
	for i=1,#set - 1 do
		local val = self:get_value(set[i])
		if t.need_258 and set[i] == set[i + 1] or (set[i] == set[i + 1] and  (val == 2 or val == 5 or val == 8)) then
			while i + 2 <= #set and set[i + 1] == set[i + 2] do
				i = i + 1
			end
			local check = {}
			for k = 1,#set do
				if k ~= i and k ~= i + 1 then
					table.insert(check,set[k])
				end
			end
			if #check == 0 or self:check_3n(check) then
				return HU
			end
		end
	end
end

function card:get_cards_num(set)
	local ret = {}
	for i=1,#set do
		local c = set[i]
		if not ret[c] then
			ret[c] = 0
		end
		ret[c] = ret[c] + 1
	end
	return ret
end

function card:check_da_si_xi(nums)
	
	for _,v in pairs(nums) do
		if v == 4 then
			return true
		end
	end
end

function card:check_banban_hu(nums)
	--local not_jiang_cards = true
	for k,v in pairs(nums) do
		local val = self:get_value(k)
		if val == 2 or val == 5 or val == 8 then
			return false
		end
	end
	return true
end

function card:check_que_yi_se(nums)
	local t_type = {}
	for k,v in pairs(nums) do
		local _type = self:get_type(k)
		t_type[_type] = true
	end
	local num = 0
	for k,v in pairs(t_type) do
		num = num + 1
	end
	if num <= 2 then
		return true
	end
end

function card:check_liu_liu_shun(nums)
	local kezi = 0
	for _,v in pairs(nums) do
		if v == 3 then
			kezi = kezi + 1
		end
	end

	if kezi >= 2 then
		return true
	end
end

function card:check_jie_jie_gao(nums)
	for k,v in pairs(nums) do
		local val = self:get_value(k)
		if val <= 7 and v == 2 and nums[k+1] == 2 and nums[k+2] == 2 then
			return true
		end
	end
end
--3同
function card:check_three_same(nums)
	for i=1,9 do
		local val = i
		local _type = 1
		if nums[16 * (_type+0) + val] and nums[16 * (_type+1) + val] and nums[16 * (_type+2) + val] then
			if nums[16 * (_type+0) + val] == 2 and nums[16 * (_type+1) + val] == 2 and nums[16 * (_type+2) + val] == 2 then
				return true
			end
		end
	end
end

function card:get_jiang_cards(nums)
	local jiang_cards = {}
	for k,v in pairs(nums) do
		local val = self:get_value(k)
		if val == 2 or val == 5 or val == 8 then
			jiang_cards[k] = v
		end
	end
	return jiang_cards
end

function card:get_cards_by_type(set)
	local t = {{},{},{}}
	for i=1,#set do
		local val = self:get_value(set[i])
		local _type = self:get_type(set[i])
		if _type >3 or _type <1 then
			skynet.error("get_cards_by_type set",string.format("%s %s \x1b[0m", "\x1b[33m",inspect(_type)))
		else
			table.insert(t[_type],set[i])
		end
	end
	return t
end

function card:check_one_flower(nums,set)
	local jiang_cards = self:get_jiang_cards(nums)
	local num = 0
	for k,v in pairs(jiang_cards) do
		num = num + v
	end
	if v == 1 and (jiang_cards[16 + 5] or jiang_cards[16 * 2 + 5] or jiang_cards[16 * 3 + 5] ) then
		return true
	end
	local cards_type = self:get_cards_by_type(set)
	for i=1,3 do
		if #cards_type[i] == 1 and self:get_value(cards_type[i][1]) == 5 then
			return true
		end
	end

end

function card:check_xiao_hu(set,t)
	if not set then
		skynet.error("set  is nil")
		return false
	end
	self:sort_card(set)
	local nums = self:get_cards_num(set)
	local ret = {}
	--大四喜
	if self:check_da_si_xi(nums) then
		table.insert(ret,XIAO_HU.DA_SI_XI)
	end
	--板板胡
	if self:check_banban_hu(nums) then
		table.insert(ret,XIAO_HU.BAN_BAN_HU)
	end
	--缺一色
	if self:check_que_yi_se(nums) then
		table.insert(ret,XIAO_HU.QUE_YI_SE)
	end
	--六六顺
	if self:check_liu_liu_shun(nums) then
		table.insert(ret,XIAO_HU.LIU_LIU_SHUN)
	end
	--节节高
	if self:check_jie_jie_gao(nums) then
		--table.insert(ret,XIAO_HU.JIE_JIE_GAO)
	end
	--3同
	if self:check_three_same(nums) then
		table.insert(ret,XIAO_HU.THREE_SAME)
	end
	--一枝花
	if self:check_one_flower(nums,set) then
		--table.insert(ret,XIAO_HU.ONE_FLOWER)
	end

	if self:check_hu(set,t) then
		--table.insert(ret,XIAO_HU.PING_HU)
	end

	return ret
end

--特殊牌型检测
function card:peng_peng_hu(set)
	cards = self:remove_gang(set)
	cards = self:remove_peng(cards)

	if #cards == 2 then 
		if cards[1] == cards[2] then
			return true
		end
	end
	
	cards = self:remove_peng(set)

	if #cards == 2 then 
		if cards[1] == cards[2] then
			return true
		end
	end

	return false
end

function card:jiang_jiang_hu(set)
	for _,v in pairs(set) do
		local val = self:get_value(v)
		--local _type = self:get_type(v)
		if val ~= 2 and val ~= 5 and val ~= 8 then
			return false
		end
	end
	return true
end

--检测清一色,混一色
function card:qing_yi_se(set)
	local color
	for _,v in pairs(set) do
		if not color then
			color = card:get_type(v)
		end
		if color ~= card:get_type(v) or card:get_type(v) == 4 then
			return false
		end
	end
	return true
end

--分离手牌和百搭牌
function card:part_cards(sets,var)
	local vars = {}
	local set = {}
	for i,v in ipairs(sets) do
		if v == var then
			table.insert(vars,v)
		else
			table.insert(set,v)
		end 
	end
	return vars,set
end

function card:check_hu_var(ori_set,t)
	if (#ori_set) %3 ~= 2 then
	 	skynet.error("check_hu_var, ori_set参数错误,参数为",inspect(ori_set))
		return
	end

	if not t then
		error("没有t 有问题")
		t = {}
	end

	self:sort_card(ori_set)
	local set = {} --其他手牌
	for i,v in ipairs(ori_set) do
		table.insert(set,v) 
	end
	--特殊牌型
	--七小对
	local qxd_set = table_copy_table(set)
	if #qxd_set == 14 then
	 local x = self:remove_dui(qxd_set)
		if #x == 0 then
			return HU
		end
	end

	if not t.chi then
		local set_t = table_copy_table(set)
		if self:peng_peng_hu(set_t) then
			return HU
		end
	end

	return self:check_hu(set,t)
end

function card:get_real_set(cards,bai_da,change)
	if #change == 0 then
		return cards
	end
	local set = {}
	local num = 0
	for _,v in pairs(cards) do
		if v ~= bai_da  then
			table.insert(set,v)
		else
			if num == #change then
				table.insert(set,v)
			else 
				num = num + 1
			end
		end
	end
	for _,v in pairs(change) do
		table.insert(set,v)
	end
	self:sort_card(set)
	return set
end

function card:get_gang_num(t)
	local nums = 0
	for i=1,#t - 3 do
		if t[i] == t[i + 1] and t[i] == t[i + 2] and t[i] == t[i + 3] then
			nums = nums + 1
		end
	end
	return nums
end


function card:seven_dui(set)
	card:sort_card(set)
	if #set ~= 14 then
		return false
	end

	-- body
	local cards = {}
	for i,v in ipairs(set) do
		table.insert(cards,v)
	end

	cards = self:remove_dui(cards)

	if #cards == 0 then
		return true
	end
	return false
end

function card:check_hu_type(t)
	local cm = {} 
	local sp  = {}
	if not t.chi and self:peng_peng_hu(t.all_set) then
		table.insert(cm,HU_TYPE.PENG_PENG_HU)
	end
	if self:qing_yi_se(t.all_set) then
		table.insert(cm,HU_TYPE.QING_ONE_SUIT)
	end
	
	if self:jiang_jiang_hu(t.all_set) then
		table.insert(cm,HU_TYPE.JIANG_JIANG_HU)
	end

	if not t.chi and self:seven_dui(t.all_set) then
		local num = card:get_gang_num(t.all_set)
		if num == 0 then
			table.insert(cm,HU_TYPE.QI_XIAO_DUI)
		elseif num == 1 then
			table.insert(cm,HU_TYPE.QI_XIAO_DUI_ONE)
		elseif num == 2 then
			table.insert(cm,HU_TYPE.QI_XIAO_DUI_TWO)
		elseif num == 3 then
			table.insert(cm,HU_TYPE.QI_XIAO_DUI_TWO)
		end
	end
	local base = true
	if #cm == 0 then
		table.insert(cm,HU_TYPE.PING_HU)
	else
		base = false
	end
	self:sort_card(cm)
	if t.hai_di_pao then
		table.insert(sp,SPECIAL_TYPE.HAI_DI_PAO)
	end
	if t.hai_di_lao_yue then
		table.insert(sp,SPECIAL_TYPE.HAI_DI_LAO_YUE)
	end
	if t.hai_di_pao then
		table.insert(sp,SPECIAL_TYPE.hai_di_pao)
	end
	if t.qiang_gang_hu then
		table.insert(sp,SPECIAL_TYPE.QIANG_GANG_HU)
	end
	if t.gang_shang_pao then
		table.insert(sp,SPECIAL_TYPE.GANG_SHANG_PAO)
	end
	if t.gang_shang_flower then
		table.insert(sp,SPECIAL_TYPE.GANG_SHANG_FLOWER)
	end
	if t.quan_qiu_ren then
		table.insert(sp,SPECIAL_TYPE.QUAN_QIU_REN)
	end
	if t.tian_hu then
		table.insert(sp,SPECIAL_TYPE.TIAN_HU)
	end
	if t.di_hu then
		table.insert(sp,SPECIAL_TYPE.DI_HU)
	end
	return cm ,base,sp
end

function card:get_base_score(t,base)
	local base_score = 0
	if base then
		base_score = 1
	else
		base_score = 3 * #t
	end
	return base_score
end

function card:check_ting(t,tb)
	local ret = {}
	for k,v in pairs(ORI_DECK) do
		local set = table_copy_table(t.set)
		table.insert(set,v)
		local hu = self:check_hu_var(set,tb)
		local all_set = table_copy_table(t.all_set)
		table.insert(all_set,v)
		if hu then
			local data = {all_set=all_set,chi=tb.chi}
			local tp,base =  self:check_hu_type(data)
			ret[v] = {}
			ret[v].type = tp
			ret[v].score  = self:get_base_score(tp,base)
			--ret[v].tai   = 1--self:get_tai_xing(data)
			--ret[v].score = SPECIAL_SCORE[hu]--self:calculate_fan_xing_num(t.lose_type,ret[v].type,ret[v].tai)
			--ret[v].tai_num = 2--self:calculate_tai_xing_num(ret[v].tai)
		end
	end
	return ret
end

function card:get_ting(t)
	local tb = {}
	local ret = {}
	tb.chi = t.chi
	tb.bai_da = t.bai_da
	for i=1,#t.set do
		tb.set = {}
		tb.all_set = {}
		local set = table_copy_table(t.set)
		card:sort_card(set)
		local c = 0
		c = table.remove(set,i)
		tb.set = set
		for _,v in pairs(set) do
			if v then
				table.insert(tb.all_set,v)
			end
		end
		for _,v in pairs(t.peng) do
			if v then
			 	table.insert(tb.all_set,v)
			end
		end
		for _,v in pairs(t.gang) do
			if v then
			 	table.insert(tb.all_set,v)
			end
		end
		for _,v in pairs(t.chi) do
			if v then 
				table.insert(tb.all_set,v)
			end
		end
		if c ~= last_c then
			--print("打出",get_c(c))
			local ting = card:check_ting(tb,t.tb)
			if next(ting) ~= nil then
				ret[c] = ting
			end
			--local str = ""
			--for k,v in pairs(ting) do
				--print(string.format("胡的牌: %s  胡牌类型: %s  番数: %d",get_c(k),get_hu_type(v.type) or "无" ,v.score))
			--end
			--print()
			--print()
		end
		last_c = c
	end
	return ret
end

--  local tb = {}
--  	tb.set = {0x16,0x17,0x18,0x19,0x38} --手牌
--  	tb.chi = {0x17,0x18,0x19,0x33,0x34,0x35}	--吃的牌
--  	tb.peng = {} --碰的牌
--  	tb.gang = {0x38,0x38,0x38,0x38} --杠的牌
-- -- 	--tb.bai_da = 0x33    --百搭牌(金牌)
-- -- local start = os.clock()
--   local x
-- -- for i=1,1 do
--  	 x= 	card:get_ting(tb)
-- -- end
--   print(inspect(x))
-- local tb = {}
-- tb.set = {17,18,18,18,22,22,35,35,49,49,49,56,56}
-- tb.all_set = {17,18,18,18,22,22,35,35,49,49,49,56,56}
-- local x = card:check_ting(tb)
 -- print(inspect(x))
-- -- print("耗时",os.clock() - start,"s")
--  print(inspect(x))
-- -- print(card:get_type(40))
-- -- print(card:get_value(40))
-- -- print(card:get_type(49))
-- -- print(card:get_value(49))

return card
